/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2010-11-18 下午01:44:30
 */
package com.webservice;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Date;

import javax.naming.InitialContext;
import javax.sql.DataSource;

import com.util.ConnUtil;

/**
 * @author zhaosj
 * 
 */
public class QuoteService {

	public String getQuoteBySymbol02(String code) {

		double bankroll = 0.0;
		long amount = 0l;
		Date tradingDay = null;

		String quoteStr = "";
		String sql = "select * from ma_position where secucode=?";

		try {

			Connection con = ConnUtil.getConnection("zhaosjOracle");
			PreparedStatement pst = con.prepareStatement(sql);
			pst.setString(1, code);
			ResultSet rs = pst.executeQuery();

			while (rs.next()) {
				bankroll = rs.getDouble("bankroll");
				amount = rs.getLong("amount");
				tradingDay = rs.getDate("tradingday");
			}
			quoteStr = code + "," + bankroll + "," + amount + "," + String.valueOf(tradingDay);

		} catch (Exception e) {
			e.printStackTrace();
		}
		return quoteStr;
	}

	public int getQuoteBySymbol01() {
		int num = 0;
		try {
			
			DbConnection db = new DbConnection();
			Connection conn= db.getCon();
			
			Statement stmt = conn.createStatement();
			String strSql = "select count(*) num from ma_history";
			ResultSet rs = stmt.executeQuery(strSql);
			while (rs.next()) {
				num = rs.getInt("num");
			}

			rs.close();
			stmt.close();
			conn.close();

		} catch (Exception e) {
			e.printStackTrace();
		} 

		return num;
	}

	public String getQuoteBySymbol(String code) {

		return code + "," + 897286.3480 + "," + 4300 + "," + "2010-9-17";
	}

	public static void main(String[] args) {
		QuoteService qs = new QuoteService();
		System.out.println(qs.getQuoteBySymbol02("000001"));
	}
}
